@extends('/admin/Layout/layout')
@section('title','评论列表')
@section('content')
<div id="page-wrapper" style="min-height: 388px;">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">评论列表--评论商品</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    商品名
                </div>
                <!-- /.panel-heading -->
                <div class="panel-body">
                    <div class="dataTable_wrapper">
                        <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                            <form action="" method="get">
                            <div class="row" style='margin-bottom:20px;'>
                                <div class="col-sm-6">
                                    <div class="dataTables_length" id="dataTables-example_length">
                                        <label>显示商品个数&nbsp; 
                                        <select name="num" aria-controls="dataTables-example" class="form-control input-sm">
                                            <option @if($num==1) selected @endif value="1">1</option>
                                            <option @if($num==3) selected @endif value="3">3</option>
                                            <option @if($num==5) selected @endif value="5">5</option>
                                            <option @if($num==10) selected @endif value="10">10</option>
                                            <option @if($num==15) selected @endif value="15">15</option>
                                        </select>&nbsp; 个</label>
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <div id="dataTables-example_filter" class="dataTables_filter">
                                    <label>
                                        <span>搜索&nbsp;&nbsp;</span><input class="form-control input-sm" placeholder="" name="likes" value="{{$likes}}" aria-controls="dataTables-example" type="search">
                                    </label>
                                    <button class="btn btn-info">查询</button>
                                    <span style='float:right;'>当前页：第&nbsp;{{$page}}&nbsp;页</span>
                                    </div>
                                </div>
                            </div>
                            </form>
                        <div class="row">
                          <div class="col-sm-12 zhongjian">
                        @foreach($comments as $k=>$v)
                        <div class="panel panel-default shangpin" >
                        <div class="panel-heading" style='text-align:center;'>
                            <span style='float:left;'>品牌：{{$v[0]->gbrand}}</span>
                            <span>{{$v[0]->gname}}</span>
                            <span style='float:right;'>商品ID：{{$v[0]->gid}}</span>
                        </div>
                        <!-- .panel-heading -->
                        <div class="panel-body" style='padding:0px;border:0px;'>
                                @foreach($v as $kk=>$vv)
                                <table class='table table-bordered'  style='border:0px;margin:0px;'>
                                    <input type="hidden" name='zid' value='{{$vv->zid}}'>
                                    <thead>
                                    <tr >
                                        <th class='col-lg-2' style='border:0px;width:120px;' >{{$vv->uname}}</th>
                                        <th style='border:0px;' class='col-lg-4'>尺码：{{$zstus[$vv->zstus]}}</th>
                                        <th style='border:0px;' class='col-lg-3'>
                                            <style type="text/css">.fa-star{color:yellow;}</style>
                                            @if($vv->zlevel==1)<span class='fa fa-star'></span>@endif
                                            @if($vv->zlevel==2)<span class='fa fa-star'></span><span class='fa fa-star'></span>@endif
                                            @if($vv->zlevel==3)<span class='fa fa-star'></span><span class='fa fa-star'></span><span class='fa fa-star'></span>@endif
                                            @if($vv->zlevel==4)<span class='fa fa-star'></span><span class='fa fa-star'></span><span class='fa fa-star'></span><span class='fa fa-star'></span>@endif
                                            @if($vv->zlevel==5)<span class='fa fa-star'></span><span class='fa fa-star'></span><span class='fa fa-star'></span><span class='fa fa-star'></span><span class='fa fa-star'></span>@endif
                                        </th>
                                        <th style='border:0px;' class='col-lg-3'>{{date('Y-m-d',$vv->ztime)}}
                                            <span style='float:right;'><button class='btn btn-danger btn-del '>删除</button></span>
                                        </th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr>
                                        @if($vv->zpic!=null)<td style='border-right:0px;width:120px;'><img  src="{{asset($vv->zpic)}}" width='100px' height='100px';></td>@endif 
                                        <td @if($vv->zpic==null) colspan='2' @endif style='height:130px;position:relative;border-left:0px;'>{{$vv->zdesc}}<button class='btn btn-primary huifu' style='position:absolute;right:0px;bottom:0px;'>回复</button></td>
                                        <td colspan='2' class='jierep' style='height:130px;'>解释：{{$vv->zreply}}</td>
                                    </tr>
                                    </tbody>
                                </table>
                                @endforeach
                        </div>
                        <!-- .panel-body -->
                    </div>
                    @endforeach
                    <div class='col-md-3'><a class='btn btn-info btn-outline btn-sm' href="{{asset('/admin/comment/index?page=1&num='.$num)}}">首页</a></div>
                    <div class='col-md-3'><a class='btn btn-info btn-outline btn-sm' href="{{asset('/admin/comment/index?page='.$prev.'&num='.$num)}}">上一页</a></div>
                    <div class='col-md-3'><a class='btn btn-info btn-outline btn-sm' href="{{asset('/admin/comment/index?page='.$next.'&num='.$num)}}">下一页</a></div>
                    <div class='col-md-3'><a class='btn btn-info btn-outline btn-sm' href="{{asset('/admin/comment/index?page='.$count.'&num='.$num)}}">尾页</a></div>
                        <style type="text/css">
                        .c1{position:fixed;left:0;right:0;top:0;bottom:0;background-color:rgba(0,0,0,0.5);z-index:1001;}
                        .detail{display:none;z-index:1003;}
                        </style>
                        <span id="cover"></span>
                        <div  class='detail' style="width:800px;position:fixed;left:285px;top:150px;margin:0;padding:0;background-color:rgba(255,255,255,0.8);border-radius:10px;">
                            <span id='dele' class='fa fa-times-circle' style='cursor:pointer;z-index:1100;float:right;margin-right:15px;margin-top:15px;'>退出</span>
                            <div class="contents" style='padding:10px;'>
                                <h3 style='text-align:center;'>评论回复</h3>
                                <textarea class="form-control"cols='10' style='width:750px;' rows="5"></textarea>
                            </div>
                            <div class="button" style='text-align:center;'>
                                <button type='button' class=' btn btn-primary btn-addhui'>提交</button>
                                <button class='btn btn-warning'>重置</button>
                            </div>
                        </div>
                    </div>
                    </div>
                    </div>
                    </div>
                </div>
                <!-- /.panel-body -->
            </div>
            <!-- /.panel -->
        </div>
        <!-- /.col-lg-12 -->
    </div>
</div>

@endsection
@section('js')
    <script type="text/javascript">
    // 回复评论
    $('.huifu').click(function(){
        //设置文档头
        $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }

        });
        //获取zid
        var btn = $(this);
        var zid = $(this).parents('table').find('input').val();
        //显示详情页面
        $('#cover').attr('class','c1');
        $('.detail').css({display:'block'});
        //添加回复
        
        $(this).parents('.zhongjian').find('.btn-addhui').unbind('click').click(function(){
            var reply = $(this).parent().siblings('.contents').find('textarea').val();
            $.post("{{asset('/admin/comment/reply')}}",{zid:zid,reply:reply},function(data){
                if(data==1){
                    //成功
                    btn.parent().siblings('.jierep').html('解释：'+reply);
                    $('#cover').removeClass('c1');
                    $('.detail').css({display:'none'});
                }else{
                    alert('添加失败');
                }
            });
        });
    });

    //退出商品详情单击事件
    $('#dele').click(function(){
        $('#cover').removeClass('c1');
        $('.detail').css({display:'none'});
    });
    //删除 
    $('.btn-del').click(function(){
        if(!confirm('是否确认删除')){
            return;
        }
        $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
        });
        //获取zid
        var btn = $(this);
        var zid = $(this).parents('table').find('input').val();
        $.get("{{asset('/admin/comment/delpl')}}",{zid:zid},function(data){
            if(data==1){
                //删除
                if(btn.parents('.shangpin').find('.table').length<=1){
                    btn.parents('.shangpin').remove();
                }else{
                    btn.parents('.table').remove();
                }
            }else{
                alert('删除失败');
            }
        });
    });
    </script>
@endsection